package com.study.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.study.bean.PictureBean;
import com.study.bean.courseBean;
import com.study.bean.scBean;
import com.study.service.impl.AddCarItemService;
import com.study.tools.MyTools;



@WebServlet("/AddCarItemControl")
public class AddCarItemControl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 request.setCharacterEncoding("utf-8");
		 response.setCharacterEncoding("utf-8");
		 try {
			String C_NAME=request.getParameter("C_NAME");
			 String C_PRICE=request.getParameter("C_PRICE");
			 courseBean pcou= new courseBean();
			 scBean sc=new scBean();
			 pcou.setC_NAME(C_NAME);//set方法输入商品颜色传到courseBean;
			 pcou.setC_PRICE(C_PRICE);//set方法输入商品颜色传到courseBean;
			 pcou.getC_NAME();
			 System.out.println("list的内容为1111111111："+pcou.getC_NAME());
			 //////////////////////获取需要加入购物车的客车的课程的信息！！！！！！
			 List<courseBean> list=MyTools.getInstance(AddCarItemService.class).getcouserInfo(pcou);
			// System.out.println("课程的内容为："+list.get(0).getC_ID());
			 //从返回的list中获取课程id
			 Integer cid=list.get(0).getC_ID();
			 request.getSession().setAttribute("c_id", list.get(0).getC_ID());
			 String hostid= request.getSession().getAttribute("Host_id").toString();
			 Integer host=new Integer(hostid);
			 //使用set方法给实体类添加值
			 sc.setC_id(cid);
			 sc.setHost_id(host);
			 sc.setSc_tag(0);
			 //System.out.println("hostid"+hostid);
			 /////////////////把host_id,c_id,sc_tag插入到数据库中
			 int listsc=MyTools.getInstance(AddCarItemService.class).getcouserInfosc(sc);
			 //System.out.println("listsc"+listsc);
			 PrintWriter pw=response.getWriter();
				// 3、根据保存处理结果进行页面转发
				if(listsc>0) {
					// 保存成功
				     pw.write(1);
			
			        
				}else {
					// 保存失败
					 pw.write(0);
				}
			  
		} catch (Exception e) {
			System.out.println("action进行了错误处理！！！！");
		}
		 
	}


}
